<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="style/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="style/js/fun.js"></script><title></title>
<style type="text/css">
.red{color:#F00;}
.underLine{text-decoration:underline;}
</style></head><body>
<span class="subTitle">php中的函数</span>
<?php
	function _addColor($text,$colorCss){
		echo "<span class=\"".$colorCss."\">".$text."</span>\n";
	}
	_addColor("Test content","red");
?>
<span class="subTitle">函数的动态调用</span>
<?php
//将函数名赋值给变量, 变量加()传入参数之后, 会自动去寻找相同函数名的函数块, 然后执行并返回相应结果.
	function _fun_1($text_1){
		echo "<em>".$text_1."</em><br />\n";
	}
	function _fun_2($text_2){
		echo "<em class=\"underLine\">".$text_2."</em>\n";
	}
	
	$test_1 = "_fun_1";
	$test_1("fun_1");
	
	$test_2 = "_fun_2";
	$test_2("fun_2");
?>
<span class="subTitle">递归(斐波那契数列)</span>
<?php
//递归要注意使用终止代码. 且尽可能是递归涉及的层小于100-200.
	function _fabanacci($num){
		if($num == 1 || $num == 2){
			return 1;
		}else{
			return _fabanacci($num - 1) + _fabanacci($num - 2);
		}
	}
	
	echo "斐波那契数列第10项为:"._fabanacci(10);
?></body>
</html>